/*
 * @Author: your name
 * @Date: 2020-02-19 10:53:40
 * @LastEditTime: 2022-03-14 11:54:59
 * @LastEditors: 郑祥
 * @Description: In User Settings Edit
 * @FilePath: \sybjgl_web\src\components\MyTable\index.js
 */

import React, { Component } from "react";
import { Table } from "antd";

export default class MyTable extends Component {
	constructor(props) {
		super(props);
		this.state = {
			size: 7,
		};
	}

	showsize = (size) => {
		if (this.props.parent && this.props.parent.sizechange) {
			this.props.parent.sizechange(this, size)
		}
	}

	render() {
		const {
			columns,
			dataSource,
			data,
			setHandler,
			onChange,
		} = this.props.props;
		return (
			<div style={{ padding: "10px" }}>
				<Table
					rowKey={(r) => r.id}
					columns={columns}
					dataSource={dataSource}
					size="middle"
					pagination={{
						total: data.total,
						defaultPageSize: 1,
						onShowSizeChange: (current, size) => {
							this.showsize(size)
							this.setState({
								size: size
							})
						},
						showSizeChanger: true,
						pageSizeOptions: [7, 10, 20, 50, 100],
						pageSize: this.state.size,
						// position: "",
						current: data.current,
						showQuickJumper: true,
						showTotal: (total, range) => `共计 ${total} 条数据`,
					}}
					onChange={onChange}
					onRow={
						setHandler
							? (record) => {
								return {
									onDoubleClick: (event) => {
										if (
											this.props.props &&
											this.props.props.permission &&
											!this.props.props.permission.review
										) {
											return;
										}
										setHandler("view", record);
									},
								};
							}
							: null
					}
					style={{ padding: "10px" }}
				/>
			</div>
		);
	}
}
